package com.ktjiaoyu.crm.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjiaoyu.crm.pojo.User;
import com.ktjiaoyu.crm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @ClassName : UserController
 * @Description :
 * @Author : Lzz
 * @Date: 2023/11/22 08:59:53
 */
@Controller
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping(value = "/user/list")
    public String findUsers(@RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,String usrName, Long roleId, Model model){
        Page<User> page = new Page<>(pageIndex,5);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();

        queryWrapper.like(StrUtil.isNotEmpty(usrName),"usr_name", usrName);
        queryWrapper.eq((ObjectUtil.isNotEmpty(roleId) && roleId!=0l),"usr_role_id", roleId);
        IPage<User> userPage = userService.findAllUserList(page, queryWrapper);
        model.addAttribute("userPager",userPage);
        //会写用户查询条件
        model.addAttribute("roleId",roleId);
        model.addAttribute("usrName",usrName);
        return "user/list";
    }

}
